wipe
model basic -ndm 3 -ndf 6
source "is_Reach_Limit.tcl"
source "SectionMesh.tcl"
source "Function.tcl"

##Component Length
set Length 2000
##Axial Load Ratio
set AxialLoadR 0.2
##Integration Points Number
set NumIntgrPts 5
##Section Height
set SecHeight 400
##Section Wdith
set SecWidth 400
##Section Cover
set Cover 20
##As in Corner
set Ascor 200
##Total As at side in X_dir without Ascor
set Asx 200
##Total As at side in Y_dir without Ascor
set Asy 200
##Bar Numbers of Asx
set AsxNum 1
##Bar Numbers of Asy
set AsyNum 1
##Concrete Material Information
set ConcreteTag 1
set fpc -20.1
set epsc0 -0.002
set fpcu -4
set epsU -0.025
##Steel Material Information
set SteelTag 2
set Fy 400
set E0 2E5
set b 0.01
##Load Increment in Cyclic Loading By Loads
set LoadIncr 1E4
##Strain Limit in Cyclic Loading By Disps
set StrainLimit 0.04
##Loading Times in one Cyclic
set Dnum 3
##Step Number in one Cyclic
set cyclic_StepNum 50

##Bottom Fixed Node
node 1 0 0 0
##Top Free Node
node 2 0 0 $Length
##Constrain
fixZ 0 1 1 1 1 1 1
##Concrete Material
uniaxialMaterial Concrete01 $ConcreteTag $fpc $epsc0 $fpcu $epsU
##Steel Material
uniaxialMaterial Steel01 $SteelTag $Fy $E0 $b
##Tranfer
geomTransf PDelta 1 1 0 0
##Rectangular Column Fiber Section:  
Fiber_Section_Proc_1 1 $SecHeight $SecWidth $Cover $Ascor $Asx $Asy $AsxNum $AsyNum $ConcreteTag $SteelTag
##Force-based Fiber Element
element forceBeamColumn 1 1 2 $NumIntgrPts 1 1

#************Gravity Analysis************#
#Axial Load
set GLoad [expr $fpc * $AxialLoadR * $SecHeight * $SecWidth]
#Define Axial Load
pattern Plain 1 Linear {
    load 2 0 0 $GLoad 0 0 0
}
#Gravity Analysis
Gravity_Proc 10
##Recorder
recorder Node -file TopDisp.txt -node 2 -dof 1 disp
recorder Node -file BaseShear.txt -node 1 -dof 1 reaction

#********Cyclic Loading By Loads*********#
#Yield Strain
set YieldStrain [expr $Fy / $E0]
#Get Postive X_dir Yield Displacement
set Pos_YeildDisp [ Get_Yeild_Disp 2 2 1 $LoadIncr $YieldStrain 1 1] 
#Get Negative X_dir Yield Displacement
set Neg_YeildDisp [ Get_Yeild_Disp 4 2 1 -$LoadIncr $YieldStrain 1 1] 
#Puts
puts "Yield Displacement: PosYield = $Pos_YeildDisp NegYield = $Neg_YeildDisp"

#********Cyclic Loading By Disps*********#
#Multiplier for Yield Displacement
set Multiplier 1
#Define Horizontal Load
pattern Plain 6 Linear {
    load 2 1E3 0 0 0 0 0
}
##Analysis Unitl Reach Strain Limit
while { "true" } {
    #Postive Target Displacement
    set PosDtarget [format "%.2f" [expr $Multiplier * $Pos_YeildDisp]]
    #Nagetive Target Displacement
    set NegDtarget [format "%.2f" [expr $Multiplier * $Neg_YeildDisp]]
    ##Dispacement Incr
    set DispIncr [expr [get_Max $PosDtarget -$NegDtarget] / $cyclic_StepNum]
    ##Puts
    puts "Cyclic Loading: PosDisp = $PosDtarget NegDisp = $NegDtarget Incr = $DispIncr"
    ##Cyclic Loading
    set ok [Cyclic_Proc $PosDtarget $NegDtarget $Dnum $DispIncr 2 1 1E-2 1 1 $StrainLimit]
    ##Analysis Fail Then Break
    if { $ok == -1 } {
        break
    } 
    incr Multiplier
}
puts "Finish Analysis"
wipe all






